import { DisplayObjectType } from "@/const"
import SourceModel from "./SourceModel"

export default class DisplayObjectModel {
    name:string
    type:DisplayObjectType
    src:string|SourceModel
    width=0
    height=0
    x=0
    y=0
    scaleX=1
    scaleY=1
    anchorX=0
    anchorY=0
    rotation=0
    alpha=1
    visible=true
    static create(data:string|any):DisplayObjectModel{
        let json:any
        if(typeof data === 'string'){
            json=JSON.parse(data)
        }else{
            json=data
        }
        const model=new DisplayObjectModel()
        model.name=json.name
        model.type=json.type
        /*switch(json.type){
            case 'image':
        }*/
        model.src=(json.src instanceof Object)?SourceModel.create(json.src):json.src
        model.width=json.width
        model.height=json.height
        model.x=json.x
        model.y=json.y
        model.scaleX=json.scaleX
        model.scaleY=json.scaleY
        model.anchorX=json.anchorX
        model.anchorY=json.anchorY
        return model
    }
}